/**
 * Created : Mar 23, 2012
 *
 * @author pquiring
 */

import java.io.*;
import javaforce.*;
import javax.swing.*;

public class MainPanel extends javax.swing.JPanel {

  /**
   * Creates new form MainPanel
   */
  public MainPanel() {
    initComponents();
    JFLog.init(JF.getUserPath() + "/.jfburn.log", true);
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        videoProject = new javax.swing.JButton();
        audioProject = new javax.swing.JButton();
        dataProject = new javax.swing.JButton();
        extractImage = new javax.swing.JButton();
        burnImage = new javax.swing.JButton();
        loadProject = new javax.swing.JButton();

        videoProject.setText("Video Project");
        videoProject.setEnabled(false);
        videoProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                videoProjectActionPerformed(evt);
            }
        });

        audioProject.setText("Audio Project");
        audioProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                audioProjectActionPerformed(evt);
            }
        });

        dataProject.setText("Data Project");
        dataProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataProjectActionPerformed(evt);
            }
        });

        extractImage.setText("Extract ISO Image");
        extractImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                extractImageActionPerformed(evt);
            }
        });

        burnImage.setText("Burn Image");
        burnImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                burnImageActionPerformed(evt);
            }
        });

        loadProject.setText("Load Project");
        loadProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadProjectActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(loadProject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(audioProject, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                    .addComponent(videoProject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dataProject, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                    .addComponent(extractImage, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                    .addComponent(burnImage, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(audioProject, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dataProject, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(videoProject, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(extractImage, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(burnImage, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(loadProject, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

  private void audioProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_audioProjectActionPerformed
    BurnApp.This.setVisible(false);
    JDialog dialog = new ProjectDialog(BurnApp.This, true, ProjectDialog.Type.audio, null);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_audioProjectActionPerformed

  private void loadProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadProjectActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    File path = new File(JF.getUserPath() + "/jfburn");
    path.mkdirs();
    chooser.setCurrentDirectory(path);
    javax.swing.filechooser.FileFilter ff_xml = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        return (file.getName().endsWith(".burn"));
      }
      public String getDescription() {
        return "Project Files (*.burn)";
      }
    };
    chooser.addChoosableFileFilter(ff_xml);
    chooser.setFileFilter(ff_xml);
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
    String filename = chooser.getSelectedFile().getAbsolutePath();
    BurnApp.This.setVisible(false);
    JDialog dialog = new ProjectDialog(BurnApp.This, true, ProjectDialog.Type.unknown, filename);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_loadProjectActionPerformed

  private void dataProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataProjectActionPerformed
    BurnApp.This.setVisible(false);
    JDialog dialog = new ProjectDialog(BurnApp.This, true, ProjectDialog.Type.data, null);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_dataProjectActionPerformed

  private void videoProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_videoProjectActionPerformed
    BurnApp.This.setVisible(false);
    JDialog dialog = new ProjectDialog(BurnApp.This, true, ProjectDialog.Type.video, null);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_videoProjectActionPerformed

  private void extractImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extractImageActionPerformed
    BurnApp.This.setVisible(false);
    JDialog dialog = new ExtractDialog(BurnApp.This, true);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_extractImageActionPerformed

  private void burnImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_burnImageActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    File path = new File(JF.getUserPath());
    chooser.setCurrentDirectory(path);
    javax.swing.filechooser.FileFilter ff_iso = new javax.swing.filechooser.FileFilter() {
      public boolean accept(File file) {
        if (file.isDirectory()) return true;
        return (file.getName().endsWith(".iso"));
      }
      public String getDescription() {
        return "ISO Files (*.iso)";
      }
    };
    chooser.addChoosableFileFilter(ff_iso);
    chooser.setFileFilter(ff_iso);
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
    String filename = chooser.getSelectedFile().getAbsolutePath();
    JDialog dialog = new BurnDialog(BurnApp.This, true, new String[] {filename});
    BurnApp.This.setVisible(false);
    dialog.setVisible(true);
    BurnApp.This.setVisible(true);
  }//GEN-LAST:event_burnImageActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton audioProject;
    private javax.swing.JButton burnImage;
    private javax.swing.JButton dataProject;
    private javax.swing.JButton extractImage;
    private javax.swing.JButton loadProject;
    private javax.swing.JButton videoProject;
    // End of variables declaration//GEN-END:variables
}
